#!/bin/bash

echo "搜寻中，请稍候..."
find / -perm +6000 > /tmp/find.r 2> /dev/null
typeset -i line_sum
line_sum=$(wc -l /tmp/find.r |cut -d' ' -f1)

typeset -i line_num
line_num=0

while read -r line
do
	line_num=$line_num+1
	array[$line_num]=$line
	echo "$line_num ${array[$line_num]}"
done < /tmp/find.r

if [ $line_num -ne $line_num ]
then
	echo "数据有变化... 请重来！"
	exit -1
fi

while true
do
	echo "请选择需要修改的文件：(以数字标记)"
	typeset -i num
	read num

	ls -l ${array[$line_num]}
	echo "是否去掉SUID属性？(Y/n)"
	read flag
	if [ -z "$flag" ]
	then
		flag=y
	fi
	sucess=0
	if [ "$flag"=="y" -o "$flag"=="Y" ];then
		chmod u-s ${array[$line_num]}

		if [ "$?" -eq $sucess ];then
			ls -l ${array[$line_num]}
			echo "修改SUID成功！"
		else
			echo "修改SUID失败！"
		fi
	elif [ "$flag"=="n" -o "$flag"=="N" ];then
		echo -e	
	else 
		echo "输入错误，请重新来过..."
		exit -1
	fi
	flag=
	echo "是否去掉SGID属性？(Y/n)"
	read flag

	if [ -z "$flag" ]
	then
		flag=y
	fi

	if [ "$flag"=="y" -o "$flag"=="Y" ];then
		chmod g-s ${array[$line_num]}
		if [ "$?" -eq $sucess ];then
			ls -l ${array[$line_num]}
			echo "修改SGID成功！"
		else
			echo "修改SGID失败！"
		fi
	elif [ "$flag"=="n" -o "$flag"=="N" ];then
		echo "Bye!"
	else 
		echo "输入错误，请重新来过..."
		exit -1
	fi
done
exit 0
